[−][src]Crate shaderc
Rust binding for the Shaderc library.
This crate contains the higher-level Rust-friendly interface for the Shaderc library. For the lower-level C interface, please see the shaderc-sys crate.
The Shaderc library provides an API for compiling GLSL/HLSL source code to SPIRV modules. It has been shipping in the Android NDK since version r12b.
The order of preference in which the build script will attempt to obtain Shaderc can be controlled by several options, which are passed through to shaderc-sys when building shaderc-rs:
- The option
--features build-from-source
will prevent automatic library detection and force building from source. - If the
SHADERC_LIB_DIR
environment variable is set to/path/to/shaderc/libs/
, it will take precedence andlibshaderc_combined.a
(and the glslang and SPIRV libraries on Linux) will be searched in the/path/to/shaderc/libs/
directory. - On Linux,
/usr/lib/
will be automatically searched for system libraries if none of the above were given. - If no other option was set or succeeded, shaderc-sys will fall back to checking out and compiling a copy of Shaderc. This procedure is quite slow.
NOTE: --no-default-features
still works on shaderc-rs, but shaderc-sys
implements this behavior in a deprecated manner, and it will be removed in
the next release. This method only works with a monolithic
libshaderc_combined.a
. Refer to pre-0.5 documentation for more
information. Prefer SHADERC_LIB_DIR="/path/to/shaderc/libs/"
.
Examples
Compile a shader into SPIR-V binary module and assembly text:
use shaderc; let source = "#version 310 es\n void EP() {}"; let mut compiler = shaderc::Compiler::new().unwrap(); let mut options = shaderc::CompileOptions::new().unwrap(); options.add_macro_definition("EP", Some("main")); let binary_result = compiler.compile_into_spirv( source, shaderc::ShaderKind::Vertex, "shader.glsl", "main", Some(&options)).unwrap(); assert_eq!(Some(&0x07230203), binary_result.as_binary().first()); let text_result = compiler.compile_into_spirv_assembly( source, shaderc::ShaderKind::Vertex, "shader.glsl", "main", Some(&options)).unwrap(); assert!(text_result.as_text().starts_with("; SPIR-V\n"));
Structs
CompilationArtifact | An opaque object containing the results of compilation. |
CompileOptions | An opaque object managing options to compilation. |
Compiler | An opaque object managing all compiler states. |
ResolvedInclude | A representation of a successfully resolved include directive, containing the name of the include and its contents. |
Enums
Error | Error. |
GlslProfile | GLSL profile. |
IncludeType | Identifies the type of include directive. |
Limit | Resource limit. |
OptimizationLevel | Optimization level. |
ResourceKind | Resource kinds. |
ShaderKind | Shader kind. |
SourceLanguage | Source language. |
TargetEnv | Target environment. |
Functions
get_spirv_version | Returns the version and revision of the SPIR-V generated by this library. |
parse_version_profile | Parses the version and profile from the given |
Type Definitions
Result | Compilation status. |